package es.usal.proyecto.Controller.Tasks;

import java.util.ArrayList;

import android.os.AsyncTask;

import com.memetix.mst.language.Language;
import com.memetix.mst.translate.Translate;

import es.usal.proyecto.Controller.Interfaces.IAsyncResponse;

public class TranslateTask extends AsyncTask<String, Integer, String> {
	public IAsyncResponse delegate=null;
	private ArrayList<Language> langs = new ArrayList<Language>(10);
	
	public TranslateTask(){
		
		langs.add(0, Language.SPANISH);
		langs.add(1, Language.ENGLISH);
		langs.add(2, Language.ITALIAN);
		langs.add(3, Language.PORTUGUESE);
	}
	
	@Override
	protected String doInBackground(String... params) {
		String translated = null;
		Translate.setClientId("salamancaOcr2014"); //Change this
        Translate.setClientSecret("ZxRbP3PUYF6icZVKm/8uJ1/2jylJd10xfPCPPkZv7oU=");  //Change this
		try {
			translated = Translate.execute(params[1], langs.get(Integer.parseInt(params[0])));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        return translated;
	}

	protected void onProgressUpdate(Integer... progress) {
    }

	@Override
    protected void onPostExecute(String result) {
		delegate.processFinish(result);
    }
 }
